package org.jeecg.modules.oms.parser;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.oms.parser.impl.optimization.ChangfengOptimizationFileProcessor;
import org.jeecg.modules.oms.parser.impl.optimization.XingeOptimizationFileProcessor;
import org.jeecg.modules.oms.parser.impl.optimization.XingeDoorOptimizationFileProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 优化单文件处理器工厂，根据优化软件类型获取对应的处理器
 */
@Slf4j
@Component
public class OptimizationFileProcessorFactory {

    /**
     * 优化软件类型：长风
     */
    public static final String OPTIMIZE_SOFTWARE_TYPE_CHANGFENG = "0";
    
    /**
     * 优化软件类型：新格尔
     */
    public static final String OPTIMIZE_SOFTWARE_TYPE_XINGE = "1";

    @Autowired
    private ChangfengOptimizationFileProcessor changfengOptimizationFileProcessor;
    
    @Autowired
    private XingeOptimizationFileProcessor xingeOptimizationFileProcessor;
    
    @Autowired
    private XingeDoorOptimizationFileProcessor xingeDoorOptimizationFileProcessor;
    
    /**
     * 根据优化软件类型获取对应的处理器
     *
     * @param optimizeSoftwareType 优化软件类型
     * @return 对应的优化单处理器
     */
    public OptimizationFileProcessor getProcessor(String optimizeSoftwareType) {
        if (StringUtils.isBlank(optimizeSoftwareType)) {
            log.error("优化软件类型为空，默认使用长风优化单处理器");
            return changfengOptimizationFileProcessor;
        }
        
        switch (optimizeSoftwareType) {
            case OPTIMIZE_SOFTWARE_TYPE_CHANGFENG:
                return changfengOptimizationFileProcessor;
            case OPTIMIZE_SOFTWARE_TYPE_XINGE:
                return xingeOptimizationFileProcessor;
            default:
                log.warn("未知的优化软件类型: {}, 默认使用长风优化单处理器", optimizeSoftwareType);
                return changfengOptimizationFileProcessor;
        }
    }

    /**
     * 根据优化软件类型和门窗类型获取对应的处理器
     *
     * @param optimizeSoftwareType 优化软件类型
     * @param windowDoorType 门窗类型 (0=窗户, 1=门)
     * @return 对应的优化单处理器
     */
    public OptimizationFileProcessor getProcessor(String optimizeSoftwareType, Integer windowDoorType) {
        if (StringUtils.isBlank(optimizeSoftwareType)) {
            log.error("优化软件类型为空，默认使用长风优化单处理器");
            return changfengOptimizationFileProcessor;
        }
        
        switch (optimizeSoftwareType) {
            case OPTIMIZE_SOFTWARE_TYPE_CHANGFENG:
                return changfengOptimizationFileProcessor;
            case OPTIMIZE_SOFTWARE_TYPE_XINGE:
                // 新格尔软件根据门窗类型细分
                if (windowDoorType != null && windowDoorType == 1) {
                    // 门类型：使用门专用处理器
                    log.info("使用新格尔门类型优化单处理器");
                    return xingeDoorOptimizationFileProcessor;
                } else {
                    // 窗户类型：使用原有新格尔处理器
                    log.info("使用新格尔窗户类型优化单处理器");
                    return xingeOptimizationFileProcessor;
                }
            default:
                log.warn("未知的优化软件类型: {}, 默认使用长风优化单处理器", optimizeSoftwareType);
                return changfengOptimizationFileProcessor;
        }
    }
}